package aiguigu1.one;

import java.util.Scanner;

/**
 * ClassName: ArrayExer03_1
 * Package: aiguigu1.one
 * Description:优化Exer03
 *
 * @Author ZY
 * @Create 2024/9/11 14:34
 * @Version 1.0
 */
public class ArrayExer03_1 {
    public static void main(String[] args) {
        //
        // 1.键盘获取学生数量,根据学生人数，穿件数组(动态初始化),数组长度为学生数量
        Scanner input = new Scanner(System.in);
        System.out.print("请输入学生人数:");
        int student = input.nextInt();
        int[] arr = new int[student];

        //2.依次从键盘获取学生成绩,并将学生成绩保存到数组元素中
        int maxScore = arr[0];
        System.out.println("请输入" + student + "个成绩:");
        for (int i = 0 ; i < arr.length ; i++){
            arr[i] = input.nextInt();
            //3.获取学生成绩的最大值
            if (maxScore < arr[i]){
                maxScore = arr[i];
            }
        }
        System.out.println("最高分是:" + maxScore);

        //4.遍历数组元素，根据学生成绩与最高分的差值，输出成绩和等级
        char grade = 0;
        for (int i = 0 ; i < arr.length ; i++) {
            if (arr[i] >= maxScore - 10) {
                grade = 'A';
            } else if (arr[i] >= maxScore - 20) {
                grade = 'B';
            } else if (arr[i] >= maxScore - 30) {
                grade = 'C';
            } else {
                grade = 'D';
            }
            System.out.println("student " + i + " score is " + arr[i] + " grade is " + grade);
        }
        input.close();
    }

}
